package com.ty.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ty.entity.OrderDetail;
import com.ty.mapper.OrderDetailMapper;
import com.ty.service.OrderDetailService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper,OrderDetail> implements OrderDetailService {

    @Autowired
    private OrderDetailMapper orderDetailMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param OrderDetailId 主键
     * @return 实例对象
     */
    @Override
    public OrderDetail queryById(Integer OrderDetailId){
        OrderDetail orderDetail= orderDetailMapper.selectById(OrderDetailId);
        return orderDetail;
    }


    /**
     * 新增数据
     *
     * @param OrderDetail 实例对象
     * @return 实例对象
     */
    public int insert(OrderDetail OrderDetail){
        orderDetailMapper.insert(OrderDetail);
        return 1;
    }

    /**
     * 更新数据
     *
     * @param orderDetail 实例对象
     * @return 实例对象
     */
    public int update(OrderDetail orderDetail){
         orderDetailMapper.update(orderDetail);
         return 1;
    }

    /**
     * 通过主键删除数据
     *
     * @param OrderDetailId 主键
     * @return 是否成功
     */
    public boolean deleteById(Integer OrderDetailId){
        int total = orderDetailMapper.deleteById(OrderDetailId);
        return total > 0;
    }

    @Override
    public int saveBatch(OrderDetail orderDetails) {
        orderDetailMapper.saveBatch(orderDetails);
        return 1;
    }

    @Override
    public List<OrderDetail> queryByOrderId(Integer orderId) {
        List<OrderDetail> orderDetails = orderDetailMapper.queryByOrderId(orderId);
        return orderDetails;
    }



}
